package java9;

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;

/**
 * @author wanyuxiang
 * @version 1.0
 * @project Java_base
 * @create 2019-08-08 14:17
 * @describe 仅供参考：https://blog.csdn.net/rickiyeat/article/details/78074292
 **/
public class HTTP2Tester {
    public static void main(String[] args) throws Exception {
        HttpClient client = HttpClient.newBuilder()
                .connectTimeout(Duration.ofSeconds(10L))
                .build();

        HttpRequest request = HttpRequest.newBuilder()
                .uri(new URI("https://www.baidu.com/"))
                .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

        System.out.println(response.statusCode());
        System.out.println(response.body());
    }
}